using System.Collections.Generic;
using UnityEngine;

public class PlayersInfoScroll : MonoBehaviour
{
	public class PlayerInfoPanelParams
	{
		public int place;

		public string league;

		public string name;

		public string state1;

		public string state2;

		public string playerId;

		public int flagScore;

		public Color bgColor;

		public Color textColor;
	}

	public UIScrollView scrollView;

	public UIGrid grid;

	public PlayerInfoPanel playerInfoPanel;

	public List<PlayerInfoPanel> playerInfoPanelList = new List<PlayerInfoPanel>();

	private void CreateInfoPanel(int place, string league, string name, string state1, string state2, Color bgColor, Color textColor, string idPlayer)
	{
		PlayerInfoPanel playerInfoPanel = Object.Instantiate(this.playerInfoPanel);
		SetUpInfoPanel(playerInfoPanel, place, league, name, state1, state2, bgColor, textColor, idPlayer);
		playerInfoPanelList.Add(playerInfoPanel);
	}

	private void SetUpInfoPanel(PlayerInfoPanel infoPanel, int place, string league, string name, string state1, string state2, Color bgColor, Color textColor, string idPlayer)
	{
		infoPanel.transform.SetParent(grid.transform);
		infoPanel.transform.localScale = Vector3.one;
		infoPanel.Init(place.ToString(), league, name, state1, state2, bgColor, textColor, idPlayer);
		infoPanel.gameObject.SetActive(true);
	}

	private void CreateInfoPanel(int place, string league, string name, string state1, string state2, Color bgColor, Color textColor, int capturedFlagScore, string idPlayer)
	{
		PlayerInfoPanel playerInfoPanel = Object.Instantiate(this.playerInfoPanel);
		SetUpInfoPanel(playerInfoPanel, place, league, name, state1, state2, bgColor, textColor, capturedFlagScore, idPlayer);
		playerInfoPanelList.Add(playerInfoPanel);
	}

	private void SetUpInfoPanel(PlayerInfoPanel infoPanel, int place, string league, string name, string state1, string state2, Color bgColor, Color textColor, int capturedFlagScore, string idPlayer)
	{
		infoPanel.transform.SetParent(grid.transform);
		infoPanel.transform.localScale = Vector3.one;
		infoPanel.Init(place.ToString(), league, name, state1, state2, bgColor, textColor, capturedFlagScore, idPlayer);
		infoPanel.gameObject.SetActive(true);
	}

	public void UpdatePlayerInfo(int place, string league, string name, string state1, string state2, Color bgColor, Color textColor, int capturedFlagScore, string idPlayer)
	{
		int num = place - 1;
		if (num < playerInfoPanelList.Count)
		{
			SetUpInfoPanel(playerInfoPanelList[num], place, league, name, state1, state2, bgColor, textColor, capturedFlagScore, idPlayer);
		}
		else
		{
			CreateInfoPanel(place, league, name, state1, state2, bgColor, textColor, capturedFlagScore, idPlayer);
		}
	}

	public void UpdatePlayerInfo(int place, string league, string name, string state1, string state2, Color bgColor, Color textColor, string idPlayer)
	{
		int num = place - 1;
		if (num < playerInfoPanelList.Count)
		{
			SetUpInfoPanel(playerInfoPanelList[num], place, league, name, state1, state2, bgColor, textColor, idPlayer);
		}
		else
		{
			CreateInfoPanel(place, league, name, state1, state2, bgColor, textColor, idPlayer);
		}
	}

	public void ClearScroll()
	{
		playerInfoPanel.gameObject.SetActive(false);
		foreach (PlayerInfoPanel playerInfoPanel in playerInfoPanelList)
		{
			playerInfoPanel.gameObject.SetActive(false);
		}
	}
}
